//===== eAthena Script ======================================= 
//= Black Jack
//===== By: ================================================== 
//= kobra_k88
//===== Current Version: ===================================== 
//= 1.0
//===== Compatible With: ===================================== 
//=
//===== Description: ========================================= 
//= Black Jack card game.  Gameplay based off standard casino
//= black jack rules.  Dealer must have at least 17 to stay and will
//= automatically stay at 17 and up.  Player must have at least
//= 13 to stay.  Aces counted as 11 or 1.  Option to "Double Down".
//= Currently does not allow for "insurance", or "splitting"
//= of pairs.
//===== Additional Comments: ================================= 
//=
//~:wack
//Pjack9685HοERO3FaѪ
//============================================================ 


cmd_in02,188,89,1	script	21Ia	57,{

	mes "[21Ia]";
	mes "An! QQӪ@21I?";
	M_Menu:
	next;
	menu "CWhO˪?",M_0, "ڭn.",L_Play, "A¤F.",M_End;

	M_0:
		mes "[21Ia]";
		mes "AQnAѭ@譱?";
		sM_Menu0:
		next;
		menu "¦ѡC",sM_0a, "ӭtWh",sM_0b, "'['C",sM_0c,
			"''ȡC",sM_0d, "SC",M_Menu;

		sM_0a:
			mes "[21Ia]";
			mes "21INO@ӯȵPCAoCؼдNOo21IΪ̬O󱵪21IAMWL21IC";
			next;
			mes "[21Ia]";
			mes "}lCeAaU`C@U`AaMaCHNo2iPC";
			mes "ھڧAWPAiH ^5533FF'P'^000000,Ϊ^5533FF'nP'^000000C";
			next;
			mes "[21Ia]";
			mes "A'P',NOiDaAݭnA[PFC";
			mes "MaܬO_nPC ";
			mes "AܤֹF^FF3355 13I ^000000~iHPC";
			mes "an^FF3355 17IΪ17IHW ^000000~iHPC";
			next;
			mes "[21Ia]";
			mes "A'nP',NOiDaA٭n[@iPC";
			mes "AiHqLnPӼW[AI.";
			mes "unASWL^FF3355 21 ^000000IAAN@iHnPC";
			goto sM_Menu0;
		sM_0b:
			mes "[21Ia]";
			mes "o̦XӭtWhG";
			next;
			mes "[21Ia]";
			mes "1.) b21I̫1^XGpGAIƤjaAANĹFCϤApGAIƤpaAANFC";
			next;
			mes "[21Ia]";
			mes "2.) pGAnF1iPӨϧAIƶWLF21IAAN鱼oCoӴNs@^5533FF'zP'^000000C";
			mes "pGazPAANĹoFoC";
			next;
			mes "[21Ia]";
			mes "3.) pGAY2iPN21IFAANĹoFoC";
			mes "AY2i1i''M1iȬ10IP,oӴNs@^5533FF'Black Jack'^000000PC";
			mes "a'Black Jack',NOaĹFC";
			next;
			mes "[21Ia]";
			mes "4.) FӭtA٦NOC";
			mes "AMaOۦPIƮɡAoشNOSӭtSĹ";
			next;
			mes "[21Ia]";
			mes "oӴNsAMa^5533FF''^000000C";
			mes "PˡAAMaPɮ'Black Jack']OoرpC";
			goto sM_Menu0;
		sM_0c:
			mes "[21Ia]";
			mes "'['NOAU`[,Oo˧ANuAn1iPC";
			mes "oӥubCĤ@^XϥΡC";
			next;
			mes "[21Ia]";
			mes "|1ӥ[ܦΪҤlNOA@}l2iP[_ӬO11IɡC";
			mes "1UiPAAܦio21IΪ20IC";
			mes "oӴNO[nɾC";
			goto sM_Menu0;
		sM_0d:
			mes "[21Ia]";
			mes "''Ob21Iߤ@@iSPA]2ӭȡC";
			mes "''iH@11I]iH@1IC";
			mes "|ҨӻAAF1i4M1iA,Ao쪺IƥiHO15IA]iHO5IC";
			next;
			mes "[21Ia]";
			mes "pGAܰPAAN۰ʳQ{O11IAAo`IƬ15I";
			next;
			mes "[21Ia]";
			mes "pGAܭnPMoF1i9AAN۰ʧ@1IAA`IƬ14IC";
			mes "pGA@11IӺAAIƴNWL21IFANW鱼oӤ";
			next;
			mes "[21Ia]";
			mes "]AbC̥iH2ӤPȡA";
			mes "ҥHoO1iD`F`P";
			goto sM_Menu0;
	M_End:
		mes "[21Ia]";
		mes "Lצɳwz";
		close;

//================
L_Play:
	mes "[21Ia]";
	mes "ЧAU`...";
	next;
	menu "2z",M_1a, "10z",M_1b, "20z",M_1c, "100z",M_1d, "ڿ骺GF....",M_End;

	M_1a:
		if(Zeny < 2) goto sL_NotEnuf;
		set @bet, 2;
		goto L_Cont0;
	M_1b:
		if(Zeny < 10) goto sL_NotEnuf;
		set @bet, 10;
		goto L_Cont0;
	M_1c:
		if(Zeny < 20) goto sL_NotEnuf;
		set @bet, 20;
		goto L_Cont0;
	M_1d:
		if(Zeny < 100) goto sL_NotEnuf;
		set @bet, 100;
		goto L_Cont0;

		sL_NotEnuf:
			mes "[21Ia]";
			mes "藍_AASӤU";
			close;

	L_Cont0:
	mes "(wP)";
	next;
	deletearray $@card[0],13;
	set @dealerTurn, 0;
	set @numP, 0;
	set @numD, 0;
	set @pAce, 0;
	set @dAce, 0;
	callsub sF_GetCards, @numP, @playCard[@numP], @playCard$[@numP], @pAce;
	callsub sF_GetCards, @numP, @playCard[@numP], @playCard$[@numP], @pAce;
	callsub sF_GetCards, @numD, @dealCard[@numD], @dealCard$[@numD], @dAce;
	callsub sF_GetCards, @numD, @dealCard[@numD], @dealCard$[@numD], @dAce;

//==============
L_Start:
	callsub sF_GetTot;

	mes "- oӬO ^FF5533a^000000 P:";
	if (@numD==2) callsub sF_D2cards;
	if (@numD==3) callsub sF_D3cards;
	if (@numD==4) callsub sF_D4cards;
	if (@numD==5) callsub sF_D5cards;
	mes "   a: ^FF5533"+@dealTot+"^000000";
	mes " ";
	mes "- oӬO ^5533FFA^000000 P:";
	if (@numP==2) callsub sF_P2cards;
	if (@numP==3) callsub sF_P3cards;
	if (@numP==4) callsub sF_P4cards;
	if (@numP==5) callsub sF_P5cards;
	if(@pAce != 1 || @playTot == 21) mes "   A: ^5533FF" +@playTot+ "^000000";
	if(@pAce == 1 && @playTot != 21) mes "   A: ^5533FF" +@playTot+ "^000000, Ϊ ^5533FF" +(@playTot-10)+ "^000000";
	next;
	if(@playTot==21 && @dealTot==21) goto sL_Push;
	if(@numP==2 && @playTot == 21) goto sL_Win;
	if(@numD==2 && @dealTot == 21) goto sL_Lose;
	if(@playTot > 21) goto sL_Lose;
	if(@dealTot > 21) goto sL_Win;
	if(@numP==2 && @dealerTurn==0) menu "I(nP)",M_Hit, "P",M_Stay, "[",M_Double;
	if(@dealerTurn == 0) menu "I(nP)",M_Hit, "P",M_Stay;

	M_Stay:
		mes "[21Ia]";
		if(@playTot < 13) goto sL_PlayToLow;
		if(@dealTot > 16) mes "aPF.";
		if(@dealTot > 16 || @numD == 5) goto L_Check;
		mes "anP...";
		next;
		callsub sF_GetCards, @numD, @dealCard[@numD], @dealCard$[@numD], @dAce;
		set @dealerTurn, 1;
		goto L_Start;

		sL_PlayToLow:
			mes "AIƤӧCఱPAAnP";
			next;
			goto M_Hit;

	M_Hit:
		if(@numP == 5) goto M_Stay;
		callsub sF_GetCards, @numP, @playCard[@numP], @playCard$[@numP], @pAce;
		goto L_Start;
	M_Double:
		mes "[21Ia]";
		mes "aܤF[. A{b`N[A";
		mes "uAA[1iP";
		next;
		set @dealerTurn, 1;
		set @bet, @bet*2;
		callsub sF_GetCards, @numP, @playCard[@numP], @playCard$[@numP], @pAce;
		goto L_Start;

//=============
L_Check:
	next;
	if(@playTot < @dealTot) goto sL_Lose;
	if(@playTot == @dealTot) goto sL_Push;

	sL_Win:
		mes "[21Ia]";
		mes "PA, AĹF!";
		next;
		set Zeny, Zeny + @bet;
		goto L_Play;
	sL_Lose:
		mes "[21Ia]";
		mes "AF";
		set Zeny, Zeny - @bet;
		next;
		goto L_Play;
	sL_Push:
		mes "[21Ia]";
		mes "oOAAMaC";
		next;
		goto L_Play;


//==================================
// Sub function for dealing/pulling the cards
sF_GetCards:
	set @rnd, rand(1,13);
	if($@card[@rnd] == 4) goto sF_GetCards;
	set $@card[@rnd], $@card[@rnd] + 1;
	set getarg(1), @rnd;
	if(getarg(1) > 10) set getarg(1), 10;
	if(getarg(1) == 1 && getarg(3) < 1) set getarg(1), 11;
	if(getarg(1) == 11) set getarg(3), 1;
	set getarg(2), " " + getarg(1) + " ";
	if(@rnd == 10) set getarg(2), getarg(1);
	if(@rnd == 1) set getarg(2), " A ";
	if(@rnd == 11) set getarg(2), " J ";
	if(@rnd == 12) set getarg(2), " Q ";
	if(@rnd == 13) set getarg(2), " K ";
	set getarg(0), getarg(0) + 1;
	return;

//==================================
// Sub function for getting the total score for each hand
sF_GetTot:
	set @i, 0;
	set @dealTot, 0;
	set @playTot, 0;

	GetDealTot:
		set @dealTot, @dealTot + @dealCard[@i];
		set @i, @i + 1;
		if(@i < @numD) goto GetDealTot;
		if(@dAce == 1 && @dealTot > 21) set @dealTot, @dealTot - 10;
		set @i, 0;
	GetPlayTot:
		set @playTot, @playTot + @playCard[@i];
		set @i, @i + 1;
		if(@i < @numP) goto GetPlayTot;
		if(@pAce == 1 && @playTot > 21) set @pAce, 2;
		if(@pAce > 0 && @playTot > 21) set @playTot, @playTot - 10;
	return;

//=======================================
// Sub function for displaying the Cards
sF_D2cards:
	mes "    .-----.   .-----. ";
	mes "    | "+@dealCard$[0]+" |   | "+@dealCard$[1]+" | ";
	mes "    '-----'   '-----' ";
	return;
sF_P2cards:
	mes "    .-----.   .-----. ";
	mes "    | "+@playCard$[0]+" |   | "+@playCard$[1]+" | ";
	mes "    '-----'   '-----' ";
	return;
sF_D3cards:
	mes "    .-----.   .-----.   .-----. ";
	mes "    | "+@dealCard$[0]+" |   | "+@dealCard$[1]+" |   | "+@dealCard$[2]+" | ";
	mes "    '-----'   '-----'    '-----' ";
	return;
sF_P3cards:
	mes "    .-----.   .-----.   .-----. ";
	mes "    | "+@playCard$[0]+" |   | "+@playCard$[1]+" |   | "+@playCard$[2]+" | ";
	mes "    '-----'   '-----'    '-----' ";
	return;
sF_D4cards:
	mes " .-----.  .-----.  .-----. ";
	mes " | "+@dealCard$[0]+" |  | "+@dealCard$[1]+" |  | "+@dealCard$[2]+" | ";
	mes " '-----'  '-----'   '-----' ";
	mes "    .-----.  ";
	mes "    | "+@dealCard$[3]+" |";
	mes "    '-----'   ";
	return;
sF_P4cards:
	mes " .-----.  .-----.  .-----. ";
	mes " | "+@playCard$[0]+" |  | "+@playCard$[1]+" |  | "+@playCard$[2]+" |";
	mes " '-----'  '-----'   '-----' ";
	mes "    .-----.  ";
	mes "    | "+@playCard$[3]+" |";
	mes "    '-----'   ";
	return;
sF_D5cards:
	mes " .-----.  .-----.  .-----. ";
	mes " | "+@dealCard$[0]+" |  | "+@dealCard$[1]+" |  | "+@dealCard$[2]+" | ";
	mes " '-----'  '-----'   '-----' ";
	mes "    .-----.   .-----. ";
	mes "    | "+@dealCard$[3]+" |   | "+@dealCard$[4]+" | ";
	mes "    '-----'   '-----' ";
	return;
sF_P5cards:
	mes " .-----.  .-----.  .-----. ";
	mes " | "+@playCard$[0]+" |  | "+@playCard$[1]+" |  | "+@playCard$[2]+" | ";
	mes " '-----'  '-----'   '-----' ";
	mes "    .-----.   .-----. ";
	mes "    | "+@playCard$[3]+" |   | "+@playCard$[4]+" | ";
	mes "    '-----'   '-----' ";
	return;
}
